//
//  IconLabel.swift
//  NGTC_iOS
//
//  Created by Mr.wang on 2018/12/25.
//  Copyright © 2018 Mr.wang. All rights reserved.
//

import UIKit

class IconLabel: UIView {
    
    let imageView = UIImageView()
    let label = UILabel()
    
    var image: UIImage? {
        set {
            imageView.image = newValue
        }
        get {
            return imageView.image
        }
    }
    
    var title: String? {
        set {
            label.text = newValue
        }
        get {
            return label.text
        }
    }
    
    var attributedText: NSAttributedString? {
        set {
            label.attributedText = newValue
        }
        get {
            return label.attributedText
        }
    }
    
    var textColor: UIColor {
        set {
            label.textColor = newValue
        }
        get {
            return label.textColor
        }
    }
    
    var font: UIFont {
        set {
            label.font = newValue
        }
        get {
            return label.font
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        imageView.contentMode = .scaleAspectFit
        addSubview(imageView)
        imageView.snp.makeConstraints { (make) in
            make.width.equalTo(imageView.snp.height)
            make.left.top.bottom.equalTo(0)
        }
        
        label.setContentCompressionResistancePriority(.required, for: .horizontal)
        label.setContentHuggingPriority(.required, for: .horizontal)
        label.textColor = UIColor.white
        addSubview(label)
        label.snp.makeConstraints { (make) in
            make.left.equalTo(imageView.snp.right).offset(10)
            make.centerY.equalTo(self.snp.centerY)
            make.right.equalTo(0)
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
